import numpy as np
import pandas as pd
# coding=utf-8
from grid_feature import *


# 加载并转换grid的poi数据
def poi_process(num, max_longitude, min_longitude, max_latitude, min_latitude):
    item_names = ['Attractions', 'Company', 'Education', 'Finance',
                  'Food', 'Government', 'Hotel', 'House', 'Life',
                  'Medical', 'Public Utilites', 'shopping', 'Transport']

    poi_counts = []
    for name in item_names:
        data = pd.read_excel("./data/厦门市POI/" + name + ".xlsx", encoding='gbk', index=False)
        data = data[data.filter(regex='^(?!Unnamed)').columns]
        data = data[(data['lng'] > min_longitude) & (data['lng'] < max_longitude) &
                    (data['lat'] > min_latitude) & (data['lat'] < max_latitude)]
        grid_id = map_grid(data['lng'], data['lat'], num, max_longitude, min_longitude, max_latitude, min_latitude)
        temp = pd.value_counts(grid_id)
        temp = temp.reset_index()
        temp.columns = ['grid_id', name]
        poi_counts.append(temp)

    poi_result = None
    for count in poi_counts:
        if poi_result is None:
            poi_result = count
        else:
            poi_result = pd.merge(poi_result, count, how='outer')
    poi_result = poi_result.fillna(0)

    poi_result.to_csv('./data/'+str(num)+'counts_POI.csv', index=False)
